package logic

import (
	"cart_srv/pb/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelLogic {
	return &DelLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DelLogic) Del(req *types.DelRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	userId := 1
	del, err := l.svcCtx.CartSrv.CartDel(l.ctx, &cart.DelCartRequest{
		UserId:  int64(userId),
		GoodsId: req.GoodsId,
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: "200",
		Msg:  "删除成功",
		Data: map[string]interface{}{
			"del": del,
		},
	}, nil
}
